package bancosys.tec.persist.entities.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import jmine.tec.persist.annotation.Alias;
import jmine.tec.persist.annotation.Comment;
import jmine.tec.persist.annotation.Comments;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.Filter;
import org.hibernate.annotations.Filters;
import org.hibernate.annotations.ForeignKey;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.DirtyAware;
import bancosys.tec.persist.bussobj.AuthPersistableBusinessObject;

@Entity
@Table(name = "FLUXO_PAGS")
@Alias("FLXPAG")
@Filters({ @Filter(name = "authFilter", condition = "auth = :auth") })
public class FluxoPagamento extends AuthPersistableBusinessObject implements Comparable<FluxoPagamento>, DirtyAware {

    private Long id;

    private Papel papel;

    private Set<Caracteristica> caracs = new HashSet<Caracteristica>();

    /**
     * @return the id
     */
    @Id
    @GeneratedValue
    public Long getId() {
        return this.id;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the papel
     */
    @ManyToOne
    @JoinColumn(name = "FK_FLUXO_PAPEL")
    @Documentation("PAPEL")
    public Papel getPapel() {
        return this.papel;
    }

    /**
     * @param papel the papel to set
     */
    public void setPapel(Papel papel) {
        this.papel = papel;
    }

    /**
     * @return the caracs
     */
    @OneToMany
    @JoinTable(name = "PAPEL_FLUXOS_CARAC_VAL", joinColumns = @JoinColumn(name = "COD_FLUXO"), inverseJoinColumns = @JoinColumn(name = "COD_CARAC_VLR"))
    @Alias("PAPFCV")
    @Comments({ @Comment(table = "PAPEL_FLUXOS_CARAC_VAL", value = "CARACS"),
            @Comment(table = "PAPEL_FLUXOS_CARAC_VAL", column = "COD_FLUXO", value = "FLUXO"),
            @Comment(table = "PAPEL_FLUXOS_CARAC_VAL", column = "COD_CARAC_VLR", value = "CARAC") })
    @ForeignKey(name = "FK_PAPFLX_PAPFCV", inverseName = "FK_CARCVL_PAPFCV")
    @Cascade({ CascadeType.ALL, CascadeType.DELETE_ORPHAN })
    public Set<Caracteristica> getCaracs() {
        return this.caracs;
    }

    /**
     * @param caracs the caracs to set
     */
    public void setCaracs(Set<Caracteristica> caracs) {
        this.caracs = caracs;
    }

    public int compareTo(FluxoPagamento o) {
        return (System.identityHashCode(this) - System.identityHashCode(o));
    }
}
